home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Games / JST / sources / OSEmu / nonvolatile.s < prev    next >
Encoding:
Text File  |  2001-03-19  |  4.4 KB  |  223 lines

  1. ;APS00000000000000000000000000000000000000000000000000000000000000000000000000000000
  2. * $Id: nonvolatile.s 1.1 1999/02/03 04:10:45 jotd Exp $
  3. **************************************************************************
  4. *   NONVOLATILE-LIBRARY                                                  *
  5. **************************************************************************
  6. **************************************************************************
  7. *   INITIALIZATION                                                       *
  8. **************************************************************************
  9.  
  10. NONVINIT    move.l    _nonvbase,d0
  11.         beq    .init
  12.         rts
  13.  
  14. .init        move.l    #162,d0        ; reserved function
  15.         move.l    #80,d1        ; 20 variables: should be OK
  16.         lea    _nonvname,a0
  17.         bsr    _InitLibrary
  18.         move.l    d0,a0
  19.         move.l    d0,_nonvbase
  20.         
  21.         patch    _LVOGetCopyNV(a0),GETCOPYNV
  22.         patch    _LVOStoreNV(a0),STORENV
  23.         patch    _LVOGetNVInfo(a0),_GetNVInfo
  24. ;        patch    _LVOGetNVList(a0),_GetNVList
  25.         patch    _LVOFreeNVData(A0),FREENVDATA
  26.  
  27.         rts
  28.  
  29. ;GetNVInfo[APTR d0](killrequesters [bool D1])
  30. _GetNVInfo:
  31. ;    moveq    #0,D0    ; not available
  32.     moveq.l    #8+8,d0
  33.     moveq.l    #0,d1
  34.     bsr.w    ForeignAllocMem
  35.     tst.l    d0
  36.     beq.s    .rts
  37.     move.l    d0,a0
  38.     move.l    d0,(A0)+
  39.     move.l    #8+8,(A0)+
  40.     move.l    #999900,(A0)    ;total storage on nv-device
  41.     move.l    #989800,4(A0)    ;free storage on nv-device
  42.     move.l    a0,d0
  43. .rts    rts
  44.  
  45.  
  46. ;GetCopyNV[APTR d0](appname[strptr a0],itemname[strptr a1],
  47. ;  killrequesters[bool d1])
  48. ;caveats: if appname+itemname becomes >32 chars the function will show
  49. ;  a requester indicating theres a problem within the function
  50. ;  (not likely as programmers chose them short to save NVRAM-space)
  51. GETCOPYNV:
  52.         link    a5,#-$40
  53. ;assemble filename, <appname>_<itemname>\0
  54.         MOVEM.L    a0-a3,-(A7)
  55.         lea.l    4*4+4(A7),a2
  56. .cpappname    tst.b    (A0)
  57.         beq.s    .endappname
  58.         move.b    (A0)+,(A2)+
  59.         bra.s    .cpappname
  60.  
  61. .endappname    move.b    #'_',(A2)+
  62. .cpitemname    tst.b    (A1)
  63.         beq.s    .enditemname
  64.         move.b    (A1)+,(A2)+
  65.         bra.s    .cpitemname
  66.  
  67. .enditemname    move.b    #0,(A2)+
  68.  
  69. ;check if file exists
  70.         lea.l    4*4+4(A7),a0
  71.         sub.l    a0,a2
  72.         cmp.l    #32,a2
  73.         bls.s    .filename_ok
  74.         pea    _LVOGetCopyNV
  75.         pea    _nonvname
  76.         bra    _emufail
  77.  
  78. .filename_ok    move.l    _RESLOAD(pc),a2
  79.         jsr    (resload_GetFileSize,a2)
  80.         tst.l    d0
  81.         beq.s    .notexisting
  82.  
  83. ;reserve mem
  84.         add.l    #$8+7,d0
  85.         and.w    #$fff8,d0
  86.         move.l    d0,4*4+4+$38(A7)
  87.         clr.l    d1
  88.         bsr.w    ForeignAllocMem
  89.         tst.l    d0
  90.         beq.s    .notexisting
  91.  
  92. ;header:
  93.         move.l    d0,a3
  94.         move.l    d0,(A3)+
  95.         move.l    4*4+4+$38(A7),d1
  96.         move.l    d1,(A3)+
  97.  
  98. ;load file into mem
  99.         addq.l    #8,d0
  100.         move.l    d0,a1
  101.         lea.l    4*4+4(A7),a0
  102.         move.l    _RESLOAD(pc),a2
  103.         jsr    (resload_LoadFile,a2)
  104.  
  105.         move.l    a3,d0
  106.         MOVEM.L    (A7)+,a0-a3
  107.         unlk    a5
  108.         rts
  109.  
  110. .notexisting    moveq    #0,D0
  111.         MOVEM.L    (A7)+,a0-a3
  112.         unlk    a5
  113.         rts
  114.  
  115. ;FreeNVData(data[APTR A0])
  116.  
  117. FREENVDATA
  118.         move.l    a0,d0
  119.         beq.s    .rts
  120.         move.l    -8(A0),a1
  121.         move.l    -4(A0),d0
  122.         bsr.w    ForeignFreeMem
  123.  
  124. .rts        rts
  125.  
  126. ;; StoreNV [error - UWORD d0](appName[STRPTR a0], itemName[STRPTR A1], 
  127. ;   data[APTR a2],length[ULONG d0], killRequesters[BOOL d1])
  128.  
  129.  
  130. STORENV:
  131.         link    a5,#-$40
  132. ;assemble filename, <appname>_<itemname>\0
  133.         MOVEM.L    a2/d0/d2-d3,-(A7)
  134.         lea.l    4*4+4(A7),a2
  135. .cpappname    tst.b    (A0)
  136.         beq.s    .endappname
  137.         move.b    (A0)+,(A2)+
  138.         bra.s    .cpappname
  139.  
  140. .endappname    move.b    #'_',(A2)+
  141. .cpitemname    tst.b    (A1)
  142.         beq.s    .enditemname
  143.         move.b    (A1)+,(A2)+
  144.         bra.s    .cpitemname
  145.  
  146. .enditemname    move.b    #0,(A2)+
  147.  
  148. ;check if file exists
  149.         lea.l    4*4+4(A7),a0
  150.         sub.l    a0,a2
  151.         cmp.l    #32,a2
  152.         bls.s    .filename_ok
  153.         pea    _LVOStoreNV
  154.         pea    _nonvname
  155.         bra    _emufail
  156.  
  157. .filename_ok
  158. ;save with dos to ensure to wipe out illegal pathnames
  159.         move.l    a0,d1
  160.         MOVE.L    #MODE_NEWFILE,D2
  161.         BSR.W    _Open
  162.         TST.L    D0
  163.         beq.s    .err
  164.         move.l    d0,a2
  165.         move.l    d0,d1
  166.         move.l    $c(A7),d2
  167.         move.l    (A7),d3        ;multiply len by 10
  168.         lsl.l    #2,d3
  169.         add.l    (A7),d3
  170.         add.l    d3,d3
  171.         bsr.w    _Write
  172.                     ;ignore any error
  173.         move.l    a2,d1
  174.         bsr.w    _Close
  175.  
  176. .err        movem.l    (A7)+,a2/d0/d2-d3
  177.         moveq    #0,D0
  178.         unlk    a5
  179.         rts
  180.  
  181.  
  182. ;GetNVList[AppName A0](killrequesters [bool D1])
  183.  
  184. _GetNVList:
  185.     movem.l    D2-D3/A2-A3,-(A7)
  186.     move.l    A0,A3        ; appname
  187.  
  188.     move.l    #MLH_SIZE,D0
  189.     move.l    #MEMF_CLEAR,D1
  190.     bsr    ForeignAllocMem
  191.     tst.l    D0
  192.     beq.b    .end
  193.     move.l    D0,A1
  194.     INITLIST
  195.  
  196.     move.l    #300,D0
  197.     move.l    #MEMF_CLEAR,D1
  198.     bsr    ForeignAllocMem
  199.     tst.l    D0
  200.     beq.b    .end
  201.  
  202.     move.l    D0,D2        ; buffer
  203.  
  204.     move.l    D0,A1
  205.     LEA    .thisdir(pc),A0        ;filename
  206.     move.l    _RESLOAD(PC),a2
  207.     move.l    #300,D0        ; buffer size
  208.     jsr    (resload_ListFiles,a2)
  209.  
  210.     ; files read, now scan names and find the ones
  211.     ; starting by AppName'_'
  212.  
  213.     move.l    D2,A0
  214.     
  215.  
  216. .end
  217.     movem.l    (A7)+,D2-D3/A2-A3
  218.     rts
  219. .thisdir:
  220.     dc.b    34,34,0
  221.     cnop    0,4
  222.  
  223.